package ObserverPattern;

import FactoryPattern.BookFactory;
import FactoryPattern.NovelFactory;
import FactoryPattern.ScienceBookFactory;
import Model.Book;
import Model.User;

import java.util.Date;

public class ObserverPatternExample {
    public static void main(String[] args) {
        // 创建图书馆
        Library library = new Library();

        // 创建用户
        User user1 = new User("Alice", "alice@example.com", "password", 25, "123 Main St");
        User user2 = new User("Bob", "bob@example.com", "password", 30, "456 Elm St");


        // 注册观察者
        library.attach(new UserObserver(user1));
        library.attach(new UserObserver(user2));

        // 添加图书
        BookFactory novelFactory = new NovelFactory();
        Book novel = novelFactory.createBook("To Kill a Mockingbird", "Harper Lee", "9780061120084", "Fiction", 281, 9.99, new Date(), 5.0);
        BookFactory scienceBookFactory = new ScienceBookFactory();
        Book scienceBook = scienceBookFactory.createBook("Data Structures", "Harper Lee", "9780061120084", "Fiction", 281, 9.99, new Date(), 5.0);
        library.addBook(scienceBook);
        library.addBook(novel);

        // 用户借书
        library.borrowBook(user1, "To Kill a Mockingbird");
        library.borrowBook(user2, "Data Structures");
    }
}
